using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

namespace SimpleFramework 
{
    public class RequestPostCommand : RequestCommand
    {
        public readonly static SimplePool<RequestPostCommand> POOL = new SimplePool<RequestPostCommand>();
        protected string m_PostData;
        protected WWWForm m_FormData;
        protected Dictionary<string, string> m_FormFields;

        public string PostData { get { return m_PostData; } set { m_PostData = value; } }
        public WWWForm FormData { get { return m_FormData; } set { m_FormData = value; } }
        public Dictionary<string, string> FormFields { get { return m_FormFields; } set { m_FormFields = value; } }

        public override void Reset()
        {
            base.Reset();
            m_PostData = null;
            m_FormData = null;
            m_FormFields = null;
        }

        protected override UnityWebRequest CreateRequest()
        {
            if (!string.IsNullOrEmpty(m_PostData))
                return UnityWebRequest.Post(m_Url, m_PostData);
            if (m_FormData != null)
                return UnityWebRequest.Post(m_Url, m_FormData);
            if (m_FormFields != null)
                return UnityWebRequest.Post(m_Url, m_FormFields);
            return null;
        }

        protected override void Recycle()
        {
            POOL.UnSpawn(this);
        }
    }
}


